﻿namespace Rende.EfTestDemo
{
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Threading.Tasks;

    public class BlogService
    {
        private BloggingContext _context;
        public BlogService(BloggingContext context)
        {
            this._context = context;
        }
        public Blog AddBlog(string name, string url)
        {
            var blog = this._context.Blogs.Add(new Blog { Name = name, Url = url });
            this._context.SaveChanges();
            return blog;
        }
        public List<Blog> GetAllBlogs()
        {
            var query = from b in this._context.Blogs
                        orderby b.Name
                        select b;
            return query.ToList();
        }
        public async Task<List<Blog>> GetAllBlogsAsync()
        {
            var query = from b in this._context.Blogs
                        orderby b.Name
                        select b;
            return await query.ToListAsync();
        }
    }
}